package com.littlecar.web.controller;

import com.littlecar.common.entity.product.Product;
import com.littlecar.web.entity.ProductInfo;
import com.littlecar.web.remote.ProductRemote;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 描述：
 *
 * @author littlecar
 * @date 2020/2/27 16:53
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductRemote productRemote;

    @RequestMapping("/getAllProducts")
    @ResponseBody
    public ProductInfo getAllProducts(@RequestParam("type") String type) {
        if (StringUtils.isEmpty(type)) {
            return new ProductInfo(0,null,0,"");
        }
        List<Product> products = productRemote.getProducts(type);
        ProductInfo productInfo = new ProductInfo();
        productInfo.setCode(0);
        productInfo.setData(products);
        productInfo.setCount(products.size());
        productInfo.setMessage("");
        return productInfo;
    }

    @RequestMapping("/productList")
    public String productList() {
        return "productList";
    }
}
